package cn.zhouchao.system.controller;

import cn.zhouchao.basic.util.AjaxResult;
import cn.zhouchao.basic.util.PageList;
import cn.zhouchao.system.domain.Systemdictionarytype;
import cn.zhouchao.system.query.SystemdictionarytypeQuery;
import cn.zhouchao.system.service.ISystemdictionarytypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 字典类型 控制类
 */
@RestController
@RequestMapping("/sysT")
public class SystemdictionarytypeController {
    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;

    /**
     *查询所有对象
     * @return
     */
    @GetMapping
    @ApiOperation(value = "查询所有对象")
    public List<Systemdictionarytype> findAll(){
        return systemdictionarytypeService.findAll();
    }

    /**
     * 查询单个对象
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "查询单个对象")
    public Systemdictionarytype findById(@PathVariable("id") Long id){
        return systemdictionarytypeService.findById(id);
    }

    /**
     * 新增或修改单个对象
     * @param systemdictionarytype
     * @return
     */
    @PutMapping
    @ApiOperation(value = "新增或修改单个对象")
    public AjaxResult saveOrUpdate(@RequestBody Systemdictionarytype systemdictionarytype){
        if (null==systemdictionarytype.getId()){
            systemdictionarytypeService.add(systemdictionarytype);
        }else {
            systemdictionarytypeService.update(systemdictionarytype);
        }
        return AjaxResult.me().success();
    }

    /**
     * 删除单个对象
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除单个对象")
    public AjaxResult delete(@PathVariable("id") Long id) {
        systemdictionarytypeService.delete(id);
        return AjaxResult.me().success();
    }

    /**
     * 分页查询
     * @param query
     * @return
     */
    @PostMapping
    @ApiOperation(value = "分页查询")
    public PageList<Systemdictionarytype> queryByPage(@RequestBody SystemdictionarytypeQuery query){
        return systemdictionarytypeService.queryByPage(query);
    }

    /**
     * 批量删除多个对象
     * 携带的时ids集合，作为对象放在RequestBody请求体中
     * 故与删除不同，就不在路径上+参数，而是通过请求体携带对象（多个）
     * @param ids
     * @return
     */
    @PatchMapping
    @ApiOperation(value = "批量删除多个对象")
    public AjaxResult batchDelete(@RequestBody List<Long> ids){
        systemdictionarytypeService.batchDelete(ids);
        return AjaxResult.me().success();
    }

}
